package Bebetter.Day04;

import java.util.Scanner;

/**
 * @Author:galaxy_yan
 * @Date: 2022/11/26
 * @Time: 11:40
 * @Description
 */
public class day04B2 {
    public static void main1(String[] args) {
//        1.接收数据
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] nums=new int[n];
        int j=0;
        while (sc.hasNext()){
            nums[j]=sc.nextInt();
            j++;
        }
//       2.数据处理
        int max=nums[0];
        int len=nums.length;
        int temp=0;
        for(int i=0;i<len;i++){
            if(temp<0){
                temp=nums[i];
            }else{
                temp+=nums[i];
            }
            if(temp>max){
                max=temp;
            }
        }
    }

    public static int GetMax(int a, int b){ //得到两个数的最大值
        return (a) > (b) ? (a) : (b);
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int size = sc.nextInt();
        int[] array = new int[size];
        for(int i = 0; i< size;i++) {
            array[i] = sc.nextInt();
        }
        int sum = array[0];
        int max = array[0];
        for(int i = 1;i < size;i++) {
            sum = GetMax(sum + array[i], array[i]); //状态方程
            if (sum >= max)
                max = sum;
        }
        System.out.println(max);
    }
}
